//
//  SwitchController.m
//  SwitchView
//
//  Created by student on 16/2/22.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "SwitchController.h"
#import "BlueViewController.h"
#import "YellowViewController.h"
@interface SwitchController ()
@property(nonatomic,strong)BlueViewController *blueVC;
@property(nonatomic,strong)YellowViewController *yellowVC;
@property(nonatomic,assign)BOOL curBlue;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *SwitchView;

@end

@implementation SwitchController
-(BlueViewController *)blueVc
{
    if(_blueVC == nil)
    {
        _blueVC = [[BlueViewController alloc]init];
        
    }
    return _blueVC;
    
    
}
- (YellowViewController *)yellowVC
{
    if(!_yellowVC)
    {
        _yellowVC = [[YellowViewController alloc] init];
    }
    return _yellowVC;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self switch:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)switch:(id)sender {
    
    [UIView beginAnimations:@"ViewFlip" context:nil];
    [UIView setAnimationDuration:1.25];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    if(self.curBlue)
    {
        [self.view insertSubview:self.yellowVC.view atIndex:0];
        [self.blueVC.view removeFromSuperview];
        [UIView setAnimationTransition:UIViewAnimationOptionTransitionFlipFromLeft forView:self.view cache:YES];
    }
    else
    {
        [self.view insertSubview:self.blueVC.view atIndex:0];
        [self.yellowVC.view removeFromSuperview];
        
        // 动画的样式
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
    }
    [UIView commitAnimations];
    self.curBlue = !self.curBlue;

}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


@end
